﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MockCommon;
using MockDataTransferObject;
using System.Globalization;

namespace Presentation.UserControl
{
    public partial class UserProfile : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        public void Binding(AbstractEntity entity)
        {
            if (entity != null)
            {
                User user = entity as User;
                Client client = entity as Client;
                Consultant consultant = entity as Consultant;
                Contractor contractor = entity as Contractor;
                if (user != null)
                {
                    UserNameLabel.Text = user.UserName;
                    RoleLabel.Text = user.Role.RoleName;
                    EmailLabel.Text = user.Email;
                    if (user.IsActive)
                    {
                        ActiveLabel.Text = "Actived";
                    }
                    else
                    {
                        ActiveLabel.Text = "Blocked";
                    }
                }
                else if (contractor != null)
                {
                    UserNameLabel.Text = contractor.User.UserName;
                    RoleLabel.Text = contractor.User.Role.RoleName;
                    EmailLabel.Text = contractor.User.Email;
                    if (contractor.User.IsActive)
                    {
                        ActiveLabel.Text = "Actived";
                    }
                    else
                    {
                        ActiveLabel.Text = "Blocked";
                    }
                    ContractorFirstNameLabel.Text = contractor.FirstName;
                    ContractorLastNameLabel.Text = contractor.LastName;
                    ContractorBirthDateLabel.Text = contractor.BirthDate.ToString("MM/dd/yyyy", CultureInfo.CurrentCulture);
                    if (contractor.Gender)
                    {
                        ContractorGenderLabel.Text = "Male";
                    }
                    else
                    {
                        ContractorGenderLabel.Text = "Female";
                    }
                    ContractorTelephone1Label.Text = contractor.Telephone1;
                    ContractorTelephone2Label.Text = contractor.Telephone2;
                    ContractorSortCodeLabel.Text = contractor.SortCode;
                    ContractorBranchLabel.Text = contractor.Branch;
                    ContractorEmailNotifyLabel.Text = ToDayInWeek(contractor.DayInWeek);
                }
                else if (client != null)
                {
                    UserNameLabel.Text = client.User.UserName;
                    RoleLabel.Text = client.User.Role.RoleName;
                    EmailLabel.Text = client.User.Email;
                    if (client.User.IsActive)
                    {
                        ActiveLabel.Text = "Actived";
                    }
                    else
                    {
                        ActiveLabel.Text = "Blocked";
                    }
                    ClientFirstNameLabel.Text = client.FirstName;
                    ClientLastNameLabel.Text = client.LastName;
                    ClientBirthDateLabel.Text = client.BirthDate.ToString("MM/dd/yyyy", CultureInfo.CurrentCulture);
                    if (client.Gender)
                    {
                        ClientGenderLabel.Text = "Male";
                    }
                    else
                    {
                        ClientGenderLabel.Text = "Female";
                    }
                    ClientAddressLabel.Text = client.Address;
                    ClientTitleLabel.Text = client.Title;
                    ClientVatNumberLabel.Text = client.VatNumber;
                    ClientRegisterNumberLabel.Text = client.RegisterNumber;
                    ClientEmailNotifyLabel.Text = ToDayInWeek(client.DayInWeek);
                    ClientPostcodeLabel.Text = client.Postcode;
                }
                else if (consultant != null)
                {
                    UserNameLabel.Text = consultant.User.UserName;
                    RoleLabel.Text = consultant.User.Role.RoleName;
                    EmailLabel.Text = consultant.User.Email;
                    if (consultant.User.IsActive)
                    {
                        ActiveLabel.Text = "Actived";
                    }
                    else
                    {
                        ActiveLabel.Text = "Blocked";
                    }
                    ConsultantFirstNameLabel.Text = consultant.FirstName;
                    ConsultantLastNameLabel.Text = consultant.LastName;
                    ConsultantBirthDateLabel.Text = consultant.BirthDate.ToString("MM/dd/yyyy", CultureInfo.CurrentCulture);
                    if (consultant.Gender)
                    {
                        ConsultantGenderLabel.Text = "Male";
                    }
                    else
                    {
                        ConsultantGenderLabel.Text = "Female";
                    }
                    ConsultantAddressLabel.Text = consultant.Address;
                }
            }
        }

        private static string ToDayInWeek(int day)
        {
            switch (day)
            {
                case 2: return "Monday";
                case 3: return "Tuesday";
                case 4: return "Wednesday";
                case 5: return "Thursday";
                case 6: return "Friday";
                case 7: return "Sarturday";
                case 8: return "Sunday";
                default: return "Direct";
            }
        }
    }
}